﻿using System;
using System.Collections.Generic;
using SmartQuant;

namespace QuantBox
{
    public static class HDataHelper
    {
        public const string UserDataName = "UserData";

        public static Instrument[] FilterInstrument(InstrumentDefinitionRequest request, IEnumerable<Instrument> instruments)
        {
            var list = new List<Instrument>();
            foreach (var inst in instruments) {
                if (request.FilterType.HasValue && request.FilterType != inst.Type) {
                    continue;
                }
                if (!string.IsNullOrEmpty(request.FilterExchange) && !string.Equals(inst.Exchange, request.FilterExchange, StringComparison.CurrentCultureIgnoreCase)) {
                    continue;
                }
                if (!string.IsNullOrEmpty(request.FilterSymbol) && !inst.Symbol.ToLower().Contains(request.FilterSymbol.ToLower())) {
                    continue;
                }
                list.Add(inst);
            }
            return list.ToArray();
        }

        public static string GetVersionString()
        {
            return QBHelper.GetVersionString(typeof(QBHistoricalData));
        }
    }
}